#!/bin/bash

# 定义需要检查的软件包列表
PACKAGES=("vim" "iproute2" "inetutils-ping" "htop" "lnav" "tree" "curl" "ripgrep" "jq" "ncdu" "gcc" "make" "zip")

# 存储缺失的软件包
MISSING_PKGS=()

# 检查每个软件包是否已安装
for pkg in "${PACKAGES[@]}"; do
    if ! dpkg -l | grep -q "^ii.*$pkg"; then
        MISSING_PKGS+=("$pkg")
        echo "[未安装] $pkg"
    else
        echo "[已安装] $pkg"
    fi
done

# 安装缺失的软件包
if [ ${#MISSING_PKGS[@]} -gt 0 ]; then
    echo "正在安装缺失的软件包: ${MISSING_PKGS[*]}"
    sudo apt update
    sudo apt install -y "${MISSING_PKGS[@]}"
else
    echo "所有软件包均已安装，无需操作。"
fi